package com.jia.leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Pro0090 {
    private List<List<Integer>> ans;
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        ans = new ArrayList<List<Integer>>();
        if(nums == null || nums.length == 0) return ans;
        Arrays.sort(nums);
        help(nums, 0, new ArrayList<Integer>());
        return ans;
    }
    private void help(int[] nums, int index, List<Integer> list) {
        ans.add(new ArrayList<Integer>(list));
        for(int i = index; i < nums.length; i++) {
            if((i>index) && (nums[i] == nums[i-1])) { continue;}
            list.add(nums[i]);
            help(nums, i + 1, list);
            list.remove(list.size() - 1);
        }
    }

    public static void main(String[] args) {
        Pro0090 pro0090 = new Pro0090();
        pro0090.subsetsWithDup(new int[]{1,2,2});
    }
}
